package com.leyou.comtroller;

import com.leyou.common.vo.PageResult;
import com.leyou.dto.PermissionDTO;
import com.leyou.service.ListService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;


@RestController
public class ListController {

    @Autowired
    private ListService listService;

    //用户页面展示
    @GetMapping("/list/page")
    public ResponseEntity<PageResult<PermissionDTO>> queryListByPage(
            @RequestParam(value = "page",defaultValue = "1")Integer page,
            @RequestParam(value = "rows",defaultValue = "5"  )Integer rows
    ){
        PageResult<PermissionDTO> pageResult = listService.queryListByPage(page, rows);
        return ResponseEntity.ok(pageResult);
    }

    //有isParent的查询
    @GetMapping("/list/of/parent")
    public ResponseEntity<List<PermissionDTO>> findPermissionByParentId(@RequestParam("pid") Long pid){
        List<PermissionDTO> list = listService.findPermissionByParentId(pid);
        return ResponseEntity.status(HttpStatus.OK).body(list);
    }

    //没有isParent的查询
    @GetMapping("/list/of/children")
    public ResponseEntity<List<PermissionDTO>> findPermissionById(@RequestParam("pid") Long pid){
        List<PermissionDTO> list = listService.findPermissionById(pid);
        return ResponseEntity.status(HttpStatus.OK).body(list);
    }

}
